<template>
  <!--评论区组件  -->
  <div id="tmp">
      <!--提交评论部分  -->
      <div class="postcomment">
        <h3> 提交评论</h3>
        <textarea placeholder="请输入你要评论的内容..." v-model="postcontent"></textarea>
        <mt-button type="primary" size="large" @click="postcomment">发表</mt-button>
      </div>
      <!--评论列表部分  -->
      <div class="list">
        <h3>评论列表</h3>
        
      </div>
  </div>
</template>
<script>
import common from "../../kits/common.js";
import {Toast} from "mint-ui";
export default {
  props:["id"],//用来接收负组件传过来的id
  data(){
    return{
      postcontent:""//双向绑定，用来自动获取用户填写的评论
    }
  },
  methods:{
    postcomment(){
      if(this.postcontent.trim().length<=0){
        Toast("评论内容不能为空，请输入")
      }
      var url=common.apidomain+"/api/postcomment/"+this.id;
      this.$http.post(url,{content:this.postcomment},{ emulateJSON: true }).then(function(res){
        Toast(res.body.message);
        this.postcontent="";
      })
    }
  }
}
</script>
<style>
.postcomment h3{
  line-height: 30px;
  border-bottom: 1px solid #bbb;
}
.postcomment textarea{
  margin-bottom:0px;
}
</style>
